package cn.rongdao.jrkabao.base;

import android.view.View;

import com.mifengkong.frtools.http.request.callback.BaseImpl;
import com.mifengkong.frtools.ui.activity.BaseActivityEvent;
import com.mifengkong.frtools.ui.fragment.FRFragment;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

import butterknife.ButterKnife;
import butterknife.Unbinder;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.disposables.Disposable;

/**
 * Created by jack on 17/5/9
 */

public abstract class BaseFragment extends FRFragment implements BaseImpl {

    private CompositeDisposable disposablesByDestroy;// 管理Destroy取消订阅者者

    private Unbinder unbinder;

    @Override
    protected void onViewReallyCreated(View view) {
        super.onViewReallyCreated(view);
        unbinder = ButterKnife.bind(this, view);
        if (null == disposablesByDestroy) {
            disposablesByDestroy = new CompositeDisposable();
        }
    }

    @Override
    public void addRxDestroy(Disposable disposable) {
        if (null != disposablesByDestroy) {
            disposablesByDestroy.add(disposable);
        }
    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void onMessageEventMainThread(BaseActivityEvent messageEvent) {
    }

    public void onDestroy() {
        super.onDestroy();
        if (null != disposablesByDestroy) {
            disposablesByDestroy.dispose();
            disposablesByDestroy = null;
        }
        if (null != unbinder) {
            unbinder.unbind();
        }
    }
}
